package com.yx.cloud.activity;

import android.content.Intent;
import android.view.View;

import com.iot.sweeper.AppContext;
import com.yx.cloud.R;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.databinding.SecuritysettingsActivityBinding;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.RomUtils;
import com.iot.common.utils.Event;

import org.greenrobot.eventbus.EventBus;import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class SecuritySettingsActivity extends BaseActivity implements View.OnClickListener {
    private SecuritysettingsActivityBinding binding;

    @Override
    protected void onCreate() {
        super.onCreate();
        binding = SecuritysettingsActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        EventBus.getDefault().register(this);
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        initView();
    }

    private  void initView(){
        String password = AppContext.get().getCurrentDevice().getCameraSettings().getGraphicPassword();
        if(password.equals("")){
            binding.rlSetPassword.setVisibility(View.VISIBLE);
            binding.rlChangePassword.setVisibility(View.INVISIBLE);
            binding.rlClosePassword.setVisibility(View.INVISIBLE);
        }else {
            binding.rlSetPassword.setVisibility(View.GONE);
            binding.rlChangePassword.setVisibility(View.VISIBLE);
            binding.rlClosePassword.setVisibility(View.VISIBLE);
        }
    }
    private void initData() {
        binding.ivSecuritySettingseReturn.setOnClickListener(this);
        binding.rlClosePassword.setOnClickListener(this);
        binding.rlChangePassword.setOnClickListener(this);
        binding.rlSetPassword.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        int id = v.getId();
        if (id == R.id.iv_securitySettingseReturn) {
            Intent_utils.backIntent(this);
        } else if (id == R.id.rl_closePassword) {
            Intent intent = new Intent(this,GraphicsPasswordActivity.class);
            intent.putExtra("tag","close");
            startActivity(intent);
        } else if (id == R.id.rl_changePassword) {
            Intent intent = new Intent(this,GraphicsPasswordActivity.class);
            intent.putExtra("tag","modify");
            startActivity(intent);
        }else if(id == R.id.rl_setPassword){
            Intent intent = new Intent(this,GraphicsPasswordActivity.class);
            intent.putExtra("tag","set");
            startActivity(intent);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Event event) {
        switch (event.getType()) {
            case Event.MESSAGE_TYPE_CAMERASETTING:
                initView();
                break;
        }
    }
}
